package com.guanyong.dao;

import com.guanyong.model.FilmModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/6/1.
 */
public interface IFilmDaoMapper {
    @Select("SELECT * FROM t_ad_film  where f_id=#{fId}")
    @ResultMap("FilmResultMap")
    FilmModel selectByPrimaryKey(String fId);

    @Select("SELECT * FROM t_ad_film  where f_id in (${idlist})")
    @ResultMap("FilmResultMap")
    List<FilmModel> selectIdList(@Param("idlist") String idlist);




    List<FilmModel> selectFilmTypeIdList(@Param("list") HashMap<String,Integer> list,
                                         @Param("count") Integer count);


    List<FilmModel> selectFilmTypeNoRepateIdList(
            @Param("typeIdlist") String  typeIdlist,
            @Param("idlist") String  idlist,

                                                 @Param("count") Integer count);


    @Update("update t_ad_film set f_commentct=f_commentct+1 where f_id=#{id}")
    int UpdateCommentCount(@Param(value = "id") String id);


    int insert(@Param(value = "record") FilmModel record);

    int update(@Param(value = "record") FilmModel record);

    @Update("update t_ad_film set f_lookct=f_lookct+1 where f_id=#{id}")
    int updatelookct(@Param(value = "id") String id);

    @Update("update t_ad_film set f_sharect=f_sharect+1 where f_id=#{id}")
    int updatesharect(@Param(value = "id") String id);

    @Update("update t_ad_film set f_collect=f_collect+1 where f_id=#{id}")
    int updatecollectct(@Param(value = "id") String id);

    @Update("update t_ad_film set f_collect=f_collect-1 where f_id=#{id}")
    int updatecollectctdel(@Param(value = "id") String id);

    @Update("update t_ad_film set f_collect=f_collect-1 where f_id in (${idlist})")
    int updatecollectctdellist(@Param(value = "idlist") String idlist);

    @Update("update t_ad_film set f_playct=f_playct+1 where f_id=#{id}")
    int updateplayct(@Param(value = "id") String id);

    @Update("update t_ad_film set f_goodct=f_lookct+1 where f_id=#{id}")
    int updategoodct(@Param(value = "id") String id);

    @Update("update t_ad_film set f_buyct=f_buyct+1 where f_id=#{id}")
    int updatebuyct(@Param(value = "id") String id);


    List<FilmModel> SelectFilmList(@Param("filmModel")FilmModel filmModel,
                                       @Param("offset")Integer offset,
                                       @Param("limit") Integer limit);

    Integer SelectFilmListCount(@Param("filmModel")FilmModel filmModel);


    @Select("SELECT * FROM (\n" +
            "SELECT * FROM t_ad_film where f_show=0 ORDER BY f_intime DESC LIMIT #{newsCount} ) " +
            "AS a \n" +
            "UNION  \n" +
            "SELECT * FROM (\n" +
            "SELECT * FROM t_ad_film  where f_show=0 ORDER BY f_playct DESC LIMIT #{hotCount}) AS B")
    @ResultMap("FilmResultMap")
    List<FilmModel> GetNewsHotFilmDaoList(@Param("newsCount") Integer newsCount, @Param
            ("hotCount") Integer hotCount);


    List<FilmModel> SelecByfPlayctFilmList(@Param("fShow") Integer fShow,
                                   @Param("limit") Integer limit);

    @Update("update t_ad_filminfo set f_stagephoto=#{fStagephoto} where f_id=#{fid}")
    Integer UpdateFilmStagephoto(@Param(value = "fid") String fid,@Param(value = "fStagephoto") String fStagephoto);


    @Select("SELECT B.* FROM (SELECT * FROM t_ad_videotosubject WHERE f_subjectid=#{subjectid}) AS A INNER" +
            " JOIN    t_ad_film  AS B\n" +
            "ON A.f_videoid=B.f_id LIMIT #{offset},#{limit}")
    @ResultMap("FilmResultMap")
    List<FilmModel> SelectBySubjectId(@Param("subjectid") Integer subjectid,
                                      @Param("offset")Integer offset,
                                      @Param("limit") Integer limit);
    @Select("SELECT count(*) FROM (SELECT * FROM t_ad_videotosubject WHERE f_subjectid=#{subjectid}) AS A " +
            "INNER" +
            " JOIN    t_ad_film  AS B\n" +
            "ON A.f_videoid=B.f_id ")
    Integer SelectBySubjectIdCount(@Param("subjectid") Integer subjectid);

    Integer SelectFilmListCount1_0(@Param("filmModel")FilmModel filmModel);

    List<FilmModel> SelectFilmList1_0(@Param("filmModel")FilmModel filmModel,
                                      @Param("offset")Integer offset,
                                      @Param("limit") Integer limit);
}
